var device = msg.payload['device'];

// 把对象的key和value分别放到两个数组中
// 例如：{a: 1, b: 2} => ['a', 'b'], [1, 2]
function objectToArrays(obj) {
  var keys = [];
  var vals = [];
  for (var key in obj) {
    if (obj.hasOwnProperty(key)) {
      keys.push(key);
      vals.push(obj[key]);
    }
  }
  return { keys, vals };
}

if (device) {
  /**
   * control 数据处理
   * @type {Object | Array}
   */
  var control = msg.payload['data']['control'];
  if (control) {
    var keys = [];
    var vals = [];
    flow.set('isControl', true);
    if (Array.isArray(control)) {
      control.forEach((item) => {
        const { keys: k, vals: v } = objectToArrays(item);
        keys.push(...k);
        vals.push(...v);
      });
    } else {
      const { keys: k, vals: v } = objectToArrays(control);
      keys.push(...k);
      vals.push(...v);
    }
    return {
      payload: vals,
      variable: keys,
    };
  }
}
return msg;
